package com.ruoyi.web.controller.help;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.help.domain.HelpStation;
import com.ruoyi.help.service.IHelpStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 消防站Controller
 * 
 * @author ruoyi
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/help/station")
public class HelpStationController extends BaseController
{
    @Autowired
    private IHelpStationService helpStationService;

    /**
     * 查询消防站列表
     */
    @PreAuthorize("@ss.hasPermi('help:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(HelpStation helpStation)
    {
        startPage();
        List<HelpStation> list = helpStationService.selectHelpStationList(helpStation);
        return getDataTable(list);
    }

    /**
     * 导出消防站列表
     */
    @PreAuthorize("@ss.hasPermi('help:station:export')")
    @Log(title = "消防站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HelpStation helpStation)
    {
        List<HelpStation> list = helpStationService.selectHelpStationList(helpStation);
        ExcelUtil<HelpStation> util = new ExcelUtil<HelpStation>(HelpStation.class);
        util.exportExcel(response, list, "消防站数据");
    }

    /**
     * 获取消防站详细信息
     */
    @PreAuthorize("@ss.hasPermi('help:station:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(helpStationService.selectHelpStationById(id));
    }

    /**
     * 新增消防站
     */
    @PreAuthorize("@ss.hasPermi('help:station:add')")
    @Log(title = "消防站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HelpStation helpStation)
    {
        return toAjax(helpStationService.insertHelpStation(helpStation));
    }

    /**
     * 修改消防站
     */
    @PreAuthorize("@ss.hasPermi('help:station:edit')")
    @Log(title = "消防站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HelpStation helpStation)
    {
        return toAjax(helpStationService.updateHelpStation(helpStation));
    }

    /**
     * 删除消防站
     */
    @PreAuthorize("@ss.hasPermi('help:station:remove')")
    @Log(title = "消防站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(helpStationService.deleteHelpStationByIds(ids));
    }
}
